<template>
	<timetable :timetables="timetables" @courseClick="get"></timetable>
</template>

<script>
	import api from '@/api/index.js'; // 引入api

	import Timetable from '@/components/lpx-timetable/lpx-timetable'
	export default {
		data() {
			return {
				timetables: [
					['大学英语', '大学英语', '', '', '', '', '毛概', '毛概', '', ''],
					['', '', '信号与系统', '信号与系统', '模拟电子技术基础', '模拟电子技术基础', '', '', '', '', ],
					['大学体育', '大学体育', '形势与政策', '形势与政策', '', '', '', '', '', ''],
					['', '', '', '', '大学物理', '大学物理', '', '', '', ''],
					['', '', 'C语言程序设计', 'C语言程序设计', '', '', '', '', '', '']
				],
				res: [],
				classes: {}
			}
		},
		components: {
			"timetable": Timetable
		},
		methods: {
			get(e) {
				let name = e['name']
				uni.showModal({
					content:this.classes[name].address,
					showCancel:false
				})
				
			},
			comp() {
				let dates = {
					"星期一": 0,
					"星期二": 1,
					"星期三": 2,
					"星期四": 3,
					"星期五": 4

				}
				let timetables = [
					['', '', '', '', '', '', '', '', '', ''],
					['', '', '', '', '', '', '', '', '', ''],
					['', '', '', '', '', '', '', '', '', ''],
					['', '', '', '', '', '', '', '', '', ''],
					['', '', '', '', '', '', '', '', '', '']
				]
				// console.log(this.classes)
				for (let key in this.classes) {
					let times = this.classes[key].time.replace("节", "").split(" ")
					let week = times[0]
					let index = times[1][0]
					// console.log(week)
					// console.log(index)
					
					timetables[dates[week]][index] = key
					timetables[dates[week]][index - 1] = key
					// console.log(key)
				}
				this.timetables = timetables
			}
		},
		onLoad() {
			let token = uni.getStorageSync("token")
			api.getClass(token).then((res) => {
				if (res.code === 1) {

					let data = res.data
					// console.log(data)
					for (let i = 0; i < data.length; i++) {
						this.classes[data[i].select.course.name] = {
							address: data[i].select.address,
							time: data[i].select.time
						}

					}
					this.comp()

				} else {
					uni.showModal({
						content: res.errors,
						showCancel: false,
						success() {
							uni.navigateBack({

							})
						}
					})
				}
			}).catch((err) => {
				console.log(err)
				
			})
		}
	}
</script>
